package com.ssm.service.impl;

import com.ssm.entity.UserEntity;
import com.ssm.mapper.UserMapper;
import com.ssm.service.UserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    public UserEntity selectUser(long id) {
        return this.userMapper.selectUser(id);
    }

    public void addUser(UserEntity userEntity) {
        if(userEntity.getUsername().trim()=="") throw new RuntimeException("用户名不可为空");
        if(userEntity.getPassword().trim()=="") throw new RuntimeException("密码不可为空");
        this.userMapper.addUser(userEntity);
    }

    public void delUser(long id) {
        this.userMapper.delUser(id);
    }

    public void updateUser(UserEntity userEntity) {
        if(userEntity.getUsername().trim()=="") throw new RuntimeException("用户名不可为空");
        if(userEntity.getPassword().trim()=="") throw new RuntimeException("密码不可为空");
        this.userMapper.updateUser(userEntity);
    }

    public List<UserEntity> userList(){
        return this.userMapper.userList();
    }

}
